home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group97a.txt / 000032_icon-group-sender _Mon Feb 3 09:15:14 1997.msg < prev    next >
Internet Message Format  |  2000-09-20  |  3KB

  1. Received: by cheltenham.cs.arizona.edu; Mon, 3 Feb 1997 13:13:23 MST
  2. Date: Mon, 3 Feb 1997 09:15:14 -0700
  3. From: swampler@noao.edu (Steve Wampler)
  4. Subject: Re: Icon Tables
  5. To: joan@cs.ucr.edu
  6. Cc: icon-group@cs.arizona.edu
  7. Message-Id: <swampler-9701031615.AA000714199@orpheus.gemini.edu>
  8. In-Reply-To: <Pine.LNX.3.95.970202145856.27059A-100000@hill.ucr.edu>
  9. Errors-To: icon-group-errors@cs.arizona.edu
  10. Status: RO
  11. Content-Length: 2227
  12.  
  13.  
  14.  
  15. Junrong Yuan wrote:
  16. > Dear Sirs
  17. >     I have a question about Icon data structure of 'table'. As I
  18. > understand it, a table is a 2D array that has a 'key', and a 'value', I 
  19. > wonder what kind of types that the  'value' field support. To be more
  20. > specific, does it support 'record' or 'list'?  The Icon book
  21. > said it can be used to implement symbol tables, etc. In the case of symbol
  22. > table, a key may correspond to several attributes,  I am thinking of
  23. > putting all the attributes in a record, but I couldn't find a way to store
  24. > a record as 'value' filed in a table. 
  25.  
  26. In Icon, any variable can hold a value of any type.  This includes the entry
  27. and value fields  of tables, sets, records, lists, whatever.  To put a record into
  28. a table, just assign an instance of the record to a table entry. E.g:
  29.  
  30.              record point(x,y,z)
  31.     .
  32.     .
  33.     .
  34.     t := table()
  35.     t["pos1"] := point(1.0,1.0,5.0)
  36.  
  37. Note that the record definition ("record point(x,y,z)") has to appear outside of
  38. any procedure definition.
  39.  
  40. >     Another question: does list support search functions? If I have 
  41. > a list of records, and I want to find a given item in the list that has a
  42. > given value in a certain record field. What shall  I do ?
  43.  
  44. If you are using Icon 9.3 and newer, there is a function sortf() that will sort
  45. a list (or table) on the basis of field values of records in the list or table.
  46. However, this does sort the entire list instead of searching it, so you would
  47. still have to search the list.
  48.  
  49. It's easy to write code to generate all records in a list list of records that have
  50. some value in a specific field, e.g.:
  51.  
  52.     every (r := !a).z = 5.0 do {
  53.          # process record r from list a, since it has a z field value of 5.0...
  54.          ...
  55.          }
  56.  
  57. or, if you actually need the list index value for some reason:
  58.  
  59.     every i := 1 to *a do {
  60.         if a[i].z = 5.0 then {
  61.              # process record a[i]...
  62.              }
  63.         }
  64.  
  65. If you are always searching the same field each time, you might consider putting
  66. the records into a table instead of a list, but this would take a bit more setup.
  67.  
  68.  
  69.     
  70. --
  71. Steve Wampler - swampler@gemini.edu [Gemini 8m Telescopes Project (under AURA)]
  72. The Gods that smiled upon your birth are laughing now. -- fortune cookie
  73.